package com.rcdz.mykotlindemo.view.fragment

import android.view.View
import androidx.fragment.app.FragmentTransaction
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.rcdz.mykotlindemo.R
import com.rcdz.mykotlindemo.model.adapter.MenuAdapter
import com.rcdz.mykotlindemo.model.adapter.TxlAdapter
import com.rcdz.mykotlindemo.model.bean.MenuInfo
import com.wjt.mylibrary.base.BaseFragment

class FragmentStart : BaseFragment() {
    lateinit var recycler_list: RecyclerView
    companion object {
        fun newInstance() = FragmentStart
    }
    override fun lazyInit() {
    }

    override fun setNowActivityName(): String {
        return "fragment_start"
    }

    override fun setLayout(): Int {
        return R.layout.fragmemt_menu
    }

    override fun initView() {
        recycler_list = getRootView().findViewById<View>(R.id.recycler_list) as RecyclerView
        recycler_list.layoutManager =  LinearLayoutManager(activity)
    }

    override fun initData() {
        var list = mutableListOf<MenuInfo>()
        var menuInfo = MenuInfo()
        menuInfo.name = "转盘转起来"
        list.add(menuInfo)

        var menuInfo2 = MenuInfo()
        menuInfo2.name = "surfaceView"
        list.add(menuInfo2)

        var menuInfo3 = MenuInfo()
        menuInfo3.name = "自定义表盘"
        list.add(menuInfo3)

        var menuInfo4 = MenuInfo()
        menuInfo4.name = "加减速度插值器"
        list.add(menuInfo4)

        var menuAdapter = MenuAdapter(activity, list, R.layout.item_menu2)
        recycler_list.adapter = menuAdapter
        menuAdapter.setOnItemClickListener { when(it){
            0->{ // 转盘
                val transaction: FragmentTransaction = activity?.supportFragmentManager!!.beginTransaction()
                transaction.replace(R.id.main_content, FragmentZhuanpan())
                transaction.addToBackStack("Zhuanpan")
                transaction.commit()
            }
            1->{ // surfaceView
                val transaction: FragmentTransaction = activity?.supportFragmentManager!!.beginTransaction()
                transaction.replace(R.id.main_content, FragmentSurfaceView())
                transaction.addToBackStack("Zhuanpan")
                transaction.commit()
            }
            2->{
                val transaction: FragmentTransaction = activity?.supportFragmentManager!!.beginTransaction()
                transaction.replace(R.id.main_content, FragmentBiaoPan())
                transaction.addToBackStack("biaopan")
                transaction.commit()
            }
            3->{
                val transaction: FragmentTransaction = activity?.supportFragmentManager!!.beginTransaction()
                transaction.replace(R.id.main_content, interpolator())
                transaction.addToBackStack("biaopan")
                transaction.commit()
            }
        } }
    }

    override fun onClick(v: View?) {
       when (v?.id){

       }
    }

}
